# Exerccio 5

# 5.1 Editando alguns parmetros grficos

setwd ("C:/Users/jess eduardo ortega/Documents/CURSO-R/Aula-4")
e.saligna <- read.table ("e.saligna.txt", header=T, sep=",")
str (e.saligna)
head (e.saligna)
plot (e.saligna$dap ~ e.saligna$ht, xlab= "ht (cm)", ylab= "DAP (cm)", las=1, tcl= 0.3, bty= "l", pch= 19, cex = 1.5, main= "Relao DAP/ht")

# 5.2 Dois grficos juntos

setwd ("C:/Users/jess eduardo ortega/Documents/CURSO-R/Aula-4")
e.saligna <- read.table ("e.saligna.txt", header=T, sep=",")
str (e.saligna)
head (e.saligna)
plot (e.saligna$dap ~ e.saligna$ht, xlab= "ht (cm)", ylab= "DAP (cm)", las=1, tcl= 0.3, bty= "l", pch= 19, cex = 1.5, main= "Relao DAP/ht")
e.saligna$talhao <- factor(e.saligna$talhao)
class (e.saligna$talhao)
par(mfrow=c(1,2))
boxplot (e.saligna$dap ~ e.saligna$talhao, xlab= "Talho", ylab= "DAP (cm)")
text (1, 22, "A", cex= 1.8)
meanDAPtalhao <- tapply (e.saligna$dap, INDEX= list(e.saligna$talhao), mean)
sdDAPtalhao <- tapply (e.saligna$dap, INDEX= list(e.saligna$talhao), sd)
sum <- (meanDAPtalhao + sdDAPtalhao)
res <- (meanDAPtalhao - sdDAPtalhao)
plot (meanDAPtalhao, xlim= c(0, 7), ylim= c(3, 25), xaxt= "n",xlab= "Talho", ylab= "DAP (cm)", main= "Relao DAP/ht",  pch= 19)   
segments (x0=1, y0=6.6, x1=1, y1=14)
segments (x0=2, y0=6.9, x1=2, y1=19)
segments (x0=3, y0=7.3, x1=3, y1=15.9)
segments (x0=4, y0=9.8, x1=4, y1=20.08)
segments (x0=5, y0=8.4, x1=5, y1=18.7)
segments (x0=6, y0=6.8, x1=6, y1=19.4)
axis (side=1, at= c(1,2,3,4,5,6), labels= c("16", "17", "18", "22", "23", "32"), las= 1)
text (1,24, "B", cex= 1.8)

# 5.3 Adivinhando o cdigo

setwd ("C:/Users/jess eduardo ortega/Documents/CURSO-R/Aula-4")
Exerccio5.3 <- read.table ("exercicio5.3.csv", header=T, sep=",")
str (Exerccio5.3)
head (Exerccio5.3)
par (mfrow=c (1,2))
par (mar= c(5.1,4.1,4.1,2.1))
modelo <- lm (Exerccio5.3$x1 ~ Exerccio5.3$y1)
plot (Exerccio5.3$x1 ~ Exerccio5.3$y1, ylim=c(0,3), xlim= c(0.5, 2.5), ylab= "Euclideam distances", xlab= "Log(Patch size)(ha)", tcl= 0.3, bty= "l",pch=17, cex=1.5)
abline (modelo, col= "black", lwd=2)
text (2.5,3, "a", cex=2)
boxplot (Exerccio5.3$x2 ~ Exerccio5.3$y2, ylim= c(0, 3.0), xlim= c(0,7), xaxt= "n", par (tcl= 0.3), par (bty="l"), cex=1.5)
axis (side=1, at=c(1,2,3,4,5,6), labels= c("Small", "Medium Edge", "Medium Interior", "Large Edge", "Large Interior", "Control"), las =1, cex=0.5) 
text (1,3.0, "*", cex=2)
text (2,3.0, "*", cex=2)
text (3,3.0, "**", cex=2)
text (4,3.0, "*", cex=2)
text (5,3.0, "***", cex=2)
text (7,3.0, "b", cex=2)
